package com.web;

import com.domain.Activity;
import com.service.activityService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 查询活动的数据
 * 接收 activityShow.jsp 页面的 activityId 数据
 * 提交到 activityService 的 findActId 函数
 * 转发到 updateActivity.jsp页面进行展示
 */
@WebServlet("/findActUpdate")
public class findActUpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.解决乱码问题
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        //2.接收活动id参数
        String activityId = request.getParameter("activityId");
        //3.进行查询这个活动
        Activity activity = new activityService().findActId(Integer.parseInt(activityId));
        //4.转发到页面/updateActivity.jsp进行展示,修改
        request.setAttribute("Activity",activity);
        request.getRequestDispatcher("/updateActivity.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
